package org.iWMS.core.dao;

import org.apache.log4j.Logger;
import org.iWMS.core.domain.User;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: issuser
 * Date: 13-5-2
 * Time: 下午3:47
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class UserDao {
    //private final static Logger logger=Logger.getLogger(UserDao.class);
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;


    public Integer getMatchCount(String userName, String password) {
        Map map = new HashMap<String, String>();
        map.put("userName", userName);
        map.put("password", password);
        return sqlSessionTemplate.selectOne("org.iWMS.core.dao.login.LoginDao.getUserCount", map);
    }

    public User findUserByUserName(String userName) {
        return sqlSessionTemplate.selectOne("org.iWMS.core.dao.login.LoginDao.selectUserByUserName", userName);
    }

    public void updateLoginInfo(final User user) {
        sqlSessionTemplate.selectOne("org.iWMS.core.dao.login.LoginDao.updateUserLoginInfo", user);
    }

    /**
     * 查询用户角色权限
     * @param user
     * @return
     */
    public List<String> findRoleByUser(User user) {
         return new ArrayList<String>();
    }

    public void updateUserById(User user) {
        sqlSessionTemplate.selectOne("org.iWMS.core.dao.login.LoginDao.updateUserById", user);
    }
}


